package com.isoft.demo01.controller;



import com.isoft.demo01.bean.BaseController;
import com.isoft.demo01.bean.ResponseData;
import com.isoft.demo01.bean.ResultCode;
import com.isoft.demo01.entity.Manage;
import com.isoft.demo01.service.impl.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/manage/manageuser")
public class ManageController extends BaseController {
    @Autowired
    ManageService manageService;

    @PostMapping
    public ResponseData add(String name){
        boolean r = manageService.add(name);
        return getResponseData(r);
    }
    @PostMapping("/login")
    public ResponseData login(@RequestBody Manage manage) {
        Map<String , Object> map = manageService.login(manage.getName(),manage.getPassword()) ;
        ResponseData res = new ResponseData() ;
        res.setErrorCode((Integer) map.get("errorCode"));
        res.setMsg(ResultCode.getMessageByCode((Integer) map.get("errorCode")));

        res.setData(map.get("data"));
        return res ;
    }
}
